package com.flex.core.utils;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.springframework.context.i18n.LocaleContextHolder;

import com.flex.constants.SystemConstants;


public class MsgUtil {

	static private ResourceBundle rb = ResourceBundle.getBundle(
			SystemConstants.MESSAGE_BUNDLE_KEY, LocaleContextHolder.getLocale());
	
	/**
	 * 获取消息
	 * @param msgCode	消息的代码
	 * @param msgArgs	消息中的参数
	 * @return
	 */
	public static String  getMessage(String msgCode, Object...msgArgs ) {
		String message = "";
		try {
			message = rb.getString(msgCode);
		} catch (MissingResourceException mse) {
			message = "msgCode is: " + msgCode
					+ ", but can't get the message of the Code";
		}
		if (msgArgs != null)
			message = MessageFormat.format(message, msgArgs);
		return message;
	}
}
